# frozen_string_literal: true

concern :AuthenticationPlugin do
  def authenticate_editor_by_token
    @current_editor = Editor.where(token: request_token).first

    raise CommonError::AuthTokenError.new unless @current_editor
  end

  def request_token
    request.headers['Authorization']
  end

  def authenticate_user_by_token
    @current_user = User.where(token: request_token).first

    raise CommonError::AuthTokenError.new unless @current_user
  end

  def request_token
    request.headers['Authorization']
  end
end
